﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class QIncom与incom区别 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AFN的区别();
        比较FN的区别();

    }


    public void 比较FN的区别()
    {
        var qdic = Qincom中的AFN处理();
        var dic = Incom中的AFN处理();

        qincomtt0.Text += "qincom中不包括的:";
        foreach (var val in dic)
        {
            if (!qdic.ContainsKey(val.Key))
            {
                qincomtt0.Text += ( Enum.GetName(typeof(QincomAFN), val.Key) + " " + val.Key.ToString("X2") + "<br/>");
            }
            else
            {
                string str = string.Empty;
                qdic[val.Key].ForEach((o) => { str += val.Value.Contains(o) ? string.Empty : ",不包括F" + o; });

                if (!string.IsNullOrEmpty(str))
                {
                    qincomtt0.Text += Enum.GetName(typeof(QincomAFN), val.Key) + str + "<br/>";
                }
            }
        }

        qincomtt0.Text += "incom中不包括的:";

        foreach (var val in qdic)
        {
            if (!dic.ContainsKey(val.Key))
            {
                qincomtt0.Text += (Enum.GetName(typeof(QincomAFN), val.Key) + " " + val.Key.ToString("X2") + "<br/>");
            }
            else
            {
                string str = string.Empty;
                dic[val.Key].ForEach((o) => { str += val.Value.Contains(o) ? string.Empty : ",不包括F" + o; });
                if (!string.IsNullOrEmpty(str))
                {
                    qincomtt0.Text += Enum.GetName(typeof(QincomAFN), val.Key) + str + "<br/>";
                }
            }
        }

    }

    public Dictionary<byte, List<string>> Qincom中的AFN处理()
    {
        Dictionary<byte, List<string>> dic = new Dictionary<byte, List<string>>();
        //        case AFN.实时数据:
        //    return new AFN_实时数据(customProtocol);
        dic.Add((byte)QincomAFN.实时数据, "1,2,4,9,16,17,21,10,11,7,3,12,6".Split(',').ToList());
        //case AFN.身份认证:
        //    return new AFN_身份认证(customProtocol);
        //3心跳
        dic.Add((byte)QincomAFN.身份认证, "1,2,3".Split(',').ToList());

        //case AFN.确认否认:
        //    return new AFN_确认否认(customProtocol);
        dic.Add((byte)QincomAFN.确认否认, "1,2".Split(',').ToList());
        //case AFN.查询参数:
        //    return new AFN_查询参数(customProtocol);
        dic.Add((byte)QincomAFN.查询参数, "1,2,3,4,5,6,7,8,9,10,11,12,13,21,22,23,31,32,33".Split(',').ToList());
        //case AFN.设置参数:
        //    return new AFN_设置参数(customProtocol);
        dic.Add((byte)QincomAFN.设置参数, "1,2,3,4,5,6,7,8,9,10,11,12,13".Split(',').ToList());
        //case AFN.终端状态:
        //    return new AFN_终端状态(customProtocol);
        dic.Add((byte)QincomAFN.终端状态, "1,2".Split(',').ToList());

        //case AFN.文件传输:
        //    return new AFN_文件传输(customProtocol);
        dic.Add((byte)QincomAFN.文件传输, "1".Split(',').ToList());

        //case AFN.控制命令:
        //    return new AFN_控制命令(customProtocol);
        dic.Add((byte)QincomAFN.控制命令, "24,1,2,3,4,5,6,7,8,31".Split(',').ToList());
        return dic;
    }
    public Dictionary<byte, List<string>> Incom中的AFN处理()
    {
        Dictionary<byte, List<string>> dic = new Dictionary<byte, List<string>>();
        dic.Add((byte)0, "2,1".Split(',').ToList());
        dic.Add((byte)2, "1,2".Split(',').ToList());
        dic.Add((byte)4, "10,11,12,13,1,2,3,4,5,6,7,8,9".Split(',').ToList());
        dic.Add((byte)5, "1,20,2,31,3,4,5,6,7,8".Split(',').ToList());
        dic.Add((byte)10, "10,11,12,13,1,21,22,23,2,31,32,33,3,4,5,6,7,8,9".Split(',').ToList());
        dic.Add((byte)12, "10,11,12,1,20,21,2,3,4,6,7,9".Split(',').ToList());
        dic.Add((byte)13, "1,2".Split(',').ToList());
        dic.Add((byte)15, "1".Split(',').ToList());
        return dic;
    }
    public Dictionary<byte, List<string>> Incom中的AFN处理逻辑()
    {
        Dictionary<byte, List<string>> dic = new Dictionary<byte, List<string>>();
        dic.Add((byte)2, "F1,F2".Split(',').ToList());
        dic.Add((byte)4, "F13,F1,F5".Split(',').ToList());
        dic.Add((byte)5, "F20,F6".Split(',').ToList());
        dic.Add((byte)13, "F1".Split(',').ToList());
        dic.Add((byte)15, "F1".Split(',').ToList());
        dic.Add((byte)10, "F33,F32,F21,F5,F1,F13".Split(',').ToList());
        return dic;
    }

    /// <summary>
    /// 两个项目AFN的区别
    /// </summary>
    public void AFN的区别()
    {
        //比较 afn
        Type qAfn = typeof(QincomAFN);
        Type afn = typeof(AFN);

        var qafndic = GetEnumList(qAfn);
        var afndic = GetEnumList(afn);
        foreach (var val in afndic)
        {
            if (!qafndic.ContainsKey(val.Key))
            {
                qincomtt.Text += (val.Value + " " + val.Key.ToString("X2") + "<br/>");
            }
        }
        foreach (var val in qafndic)
        {
            if (!afndic.ContainsKey(val.Key))
            {
                qincomtt.Text += (val.Value + " " + val.Key.ToString("X2") + "<br/>");
            }
        }
    }

    /// <summary>
    /// 获取枚举
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    public Dictionary<byte, string> GetEnumList(Type type)
    {
        Dictionary<byte, string> result = new Dictionary<byte, string>();
        foreach (string name in type.GetEnumNames())
        {
            result.Add((byte)Enum.Parse(type, name), name);
        }



        return result;

    }

}